package com.isoft.airportsystem.service.impl;


import com.isoft.airportsystem.entity.DFDL.*;
import com.isoft.airportsystem.mapper.DfdlMapper;
import com.isoft.airportsystem.service.DfdlService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class DfdlServiceImpl implements DfdlService {

    @Resource
    private DfdlMapper dfdlMapper;

    @Override
    public void insert(MSG23 msg) {

        String dfdl_uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();

        dfdlMapper.addMeta(dfdl_uuid, msg.getMeta());

        dfdlMapper.addMSG(dfdl_uuid, msg);

        List<DFLT> data = msg.getData();
        for (DFLT dflt : data) {

            List<ARPT> arpts = dflt.getARPT();
            for (ARPT arpt : arpts) {

                dfdlMapper.addArpt(dfdl_uuid, arpt);
            }
            List<BELT> belts = dflt.getBELT();
            for (BELT belt : belts) {

                dfdlMapper.addBelt(dfdl_uuid, belt);
            }


            List<SFLT> sflt = dflt.getSflt();
            for (SFLT sflt1 : sflt) {

                dfdlMapper.addSflt(dfdl_uuid, sflt1);
            }
            dfdlMapper.addDflt(dfdl_uuid, dflt, dflt.getCkls(), dflt.getTMCD());
        }
    }
}
